{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf380
{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fnil\fcharset77 Monaco;\f2\fswiss\fcharset77 Helvetica;
}
{\colortbl;\red255\green255\blue255;\red0\green0\blue191;\red96\green96\blue96;\red191\green0\blue0;
\red0\green115\blue0;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\b\fs36 \cf0 CQ_Diff		Logarithmic spectral difference measure
\f1\b0\fs40 \

\fs18 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b\fs24 \cf0 CQ_Diff.kr(in1, in2, databufnum)\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f2\b0 \cf0 A measure of spectral difference. Uses the "Constant Q" transformation to analyse on a logarithmic frequency scale, which hopefully avoids one problem with difference measures based directly on FFT bin differences, namely that its linear frequency scale can end up prioritising the higher frequencies. The comparison is still quite crude, however. Weighting of frequency bins according to known perceptual curves would be one way to improve the comparison, but has not been implemented here.\
\
The constant Q code has largely been stolen from the \ul [Qitch]\ulnone  UGen. As with that UGen, you MUST initialise it with a suitable auxiliary data file - please read the Qitch helpfile for more details.\
\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b \cf0 Example:\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f2\b0 \cf0 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f1\fs18 \cf0 s = \cf2 Server\cf0 .local.boot;\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li1700\fi-1700\ql\qnatural
\cf0 b = \cf2 Buffer\cf0 .read(s, \cf3 "QspeckernN2048SR44100.wav"\cf0 ); \
\cf4 //this line is absolutely essential! You must load the data required by the UGen! \cf0 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\cf0 \
( \cf4 // The left and right channel will be compared...\cf0 \
x = \{	\cf2 |f1=440, f2=440, n1=0, n2=0, v1=1, v2=1|\cf0 \
	[\
		\cf2 SinOsc\cf0 .ar(f1, 0, 0.3) + \cf2 WhiteNoise\cf0 .ar(n1) * v1,\
		\cf2 SinOsc\cf0 .ar(f2, 0, 0.3) + \cf2 WhiteNoise\cf0 .ar(n2) * v2\
	]\
\}.play(s);\
)\
\
(\
y = \{\
	\cf2 var\cf0  l,r;\
	\
	# l, r = \cf2 In\cf0 .ar([0,1]);\
	\
	\cf2 CQ_Diff\cf0 .kr(l, r, b.bufnum).poll(3, \cf3 "CQ_Diff:"\cf0 );\
\}.play(s, addAction: \cf5 \\addToTail\cf0 );\
)\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\cf4 // Now vary the left and right channels...\cf0 \
x.set(\cf5 \\f1\cf0 , 439);\
x.set(\cf5 \\f1\cf0 , 139);\
x.set(\cf5 \\f1\cf0 , 1440);\
x.set(\cf5 \\f1\cf0 , 440);\
x.set(\cf5 \\n1\cf0 , 0.1);\
x.set(\cf5 \\n1\cf0 , 0.3);\
x.set(\cf5 \\n1\cf0 , 0.9);\
x.set(\cf5 \\n1\cf0 , 0.0);\
x.set(\cf5 \\v1\cf0 , 0.0);\
x.set(\cf5 \\v2\cf0 , 0.0);\
\cf4 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\cf0 x.free;\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\cf4 // Also try it with this test signal:\cf0 \
(\
x = \{	\cf2 |f1=440, f2=440|\cf0 \
	[\
		\cf2 LPF\cf0 .ar(\cf2 WhiteNoise\cf0 .ar, f1),\
		\cf2 LPF\cf0 .ar(\cf2 WhiteNoise\cf0 .ar, f2)\
	]\
\}.play(s);\
)\cf4 \
}